namespace ScrumSprintMonitor.Modules.BuildMonitor.ViewModels
{
	#region #using Directives

	using System.Windows.Media;

	using Infrastructure;

	using Microsoft.Practices.ServiceLocation;

	#endregion

	public class BuildStatusBackgroundViewModel : BuildViewModelBase,
	                                              IBuildStatusBackgroundViewModel
	{
		static BuildStatusBackgroundViewModel()
		{
			var dependsOn = Register<BuildStatusBackgroundViewModel>();

			dependsOn.Call(me => me.OnPropertyChanged("BuildStatus")).OnChanged(me => me.ReportableData.LastBuild.Status);

			dependsOn.Call(me => me.OnPropertyChanged("BuildStatusColor")).OnChanged(me => me.BuildStatus);
		}

		public BuildStatusBackgroundViewModel(IServiceLocator serviceLocator)
			: base(serviceLocator)
		{
		}

		#region IBuildStatusBackgroundViewModel Members

		public BuildStatus BuildStatus
		{
			get
			{
				EnsureConnected();
				return (LastBuild != null ? LastBuild.Status : BuildStatus.NotSetUp);
			}
		}

		public Color BuildStatusColor
		{
			get
			{
				GuardDisposed();

				switch (BuildStatus)
				{
					case BuildStatus.NotSetUp:
						break;
					case BuildStatus.Failed:
						return Colors.Red;
					case BuildStatus.NotStarted:
					case BuildStatus.InProgress:
						return Colors.Black;
					case BuildStatus.PartiallySucceeded:
						return Colors.DarkOrange;
					case BuildStatus.Stopped:
						return Colors.Blue;
					case BuildStatus.Succeeded:
						return Colors.Green;
				}

				return Colors.Transparent;
			}
		}

		#endregion
	}
}